<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('列表')" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								时间：<input type="text" class="input_time" id="begin" placeholder="时间" name="begin"/>
							</li>

							<li>
								代付状态：<select name="status" id="status">
								<option value="" selected>所有</option>
								<option value="1">下单失败</option>
								<option value="2">下单超时</option>
								<option value="3">待结算</option>
								<option value="4">未代付</option>
								<option value="5">已代付</option>
								<option value="6">审核中</option>
								</select>
							</li>

							<li>
								平台编号：<input type="text" name="code"/>
							</li>

							<li>
								渠道编号：<input type="text" name="chCode"/>
							</li>

							<li>
								商户编号：<input type="text" name="mchCode"/>
							</li>

							<li>
								商户名称：<input type="text" name="merchantName"/>
							</li>

							<li>
								渠道名称：<input type="text" name="channelName"/>
							</li>

							<li>
								钱包名称：<input type="text" name="walletKindName"/>
							</li>

							<li>
								账户号：<input type="text" name="bankAccountNo"/>
							</li>

							<li>
								账户类型：<select name="bankAccountType" id="bankAccountType">
								<option value="" selected>所有</option>
								<option value="0">对私</option>
								<option value="1">对公</option>
							</select>
							</li>

							<li>
								商户通知状态：<select name="merchantNotifyStatus" id="merchantNotifyStatus">
								<option value="" selected>所有</option>
								<option value="-1">无效</option>
								<option value="0">未通知</option>
								<option value="1">已通知</option>
							</select>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="withdrawalSearch()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="resetWithdrawalParam()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="transaction:transactionWithdrawal:export">
						<i class="fa fa-download"></i> 导出
				 </a>
				<a class="btn btn-success" onclick="verification()" shiro:hasPermission="merchant:mpMerchantWallet:withdrawal">
					<i class="fa fa-plus"></i> 核销
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true" class="table text-nowrap"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('transaction:transactionWithdrawal:edit')}]];
        var removeFlag = [[${@permission.hasPermi('transaction:transactionWithdrawal:remove')}]];
        var prefix = ctx + "transaction/transactionWithdrawal";


        var $form = $("#formId");
        // 初始化默认时间值
        var time = new Date();
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        // var d = time.getDate();
        function add0(m) {
            return m < 10 ? '0' + m : m
        }
		var nowTime = y + '-' + add0(m);
        $form.find("input[name='begin']").val(nowTime);


        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "",
                queryParams: queryParams,
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : '标识',
					visible: false
				},
                {
                    field : 'begin',
                    title : '开始时间',
                },
				{
					field : 'code', 
					title : '平台编号',
				},
				{
					field : 'chCode', 
					title : '渠道编号',
				},
				{
					field : 'mchCode', 
					title : '商户编号',
				},
				{
					field : 'fee',
					title : '代付金额(元)',
                    formatter: function (value, row, index) {
					    if (value != null) {
                            var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                            return data;
						}
                    }
				},
                {
                    field : 'subFee',
                    title : '申请金额(元)',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                            return data;
                        }
                    }
                },
				{
					field : 'chFee',
					title : '渠道出账(元)',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                            return data;
                        }
                    }
				},
				{
					field : 'mchFee',
					title : '商户出账(元)',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                            return data;
                        }
                    }
				},
				{
					field : 'finFee',
					title : '财务入账(元)',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                            return data;
                        }
                    }
				},
				{
					field : 'status',
					title : '代付状态',
                    formatter: function (value, row, index) {
					    if (value === 1) {
                            return '<span class="badge badge-danger">下单失败</span>';
                        }else if (value === 2) {
                            return '<a class="btn btn-danger btn-xs ' + '" href="#" onclick= "orderConfirm(\'' + row.id + '\')"><i class="fa fa-refresh"></i>下单超时</a> ' +
                            '<a class="btn btn-danger btn-xs ' + '" href="#" onclick= "confirmWithdawal(\'' + row.code + '\', 1)"><i class="fa fa-refresh"></i>确认失败</a> ' +
                            '<a class="btn btn-warning btn-xs ' + '" href="#" onclick= "confirmWithdawal(\'' + row.code + '\', 2)"><i class="fa fa-refresh"></i>确认放款</a> ';;
                        }else if (value === 3) {

                            return '<a class="btn btn-warning btn-xs ' + '" href="#" onclick= "orderConfirm(\'' + row.id + '\')"><i class="fa fa-refresh"></i>待结算</a> ' +
                                '<a class="btn btn-danger btn-xs ' + '" href="#" onclick= "confirmWithdawal(\'' + row.code + '\', 1)"><i class="fa fa-refresh"></i>确认失败</a> '+
                                '<a class="btn btn-warning btn-xs ' + '" href="#" onclick= "confirmWithdawal(\'' + row.code + '\', 2)"><i class="fa fa-refresh"></i>确认放款</a> ';
                        }else if (value === 4 ) {
                            return '<span class="badge badge-danger">未代付</span> ';
						}else if (value === 5) {
                            return '<span class="badge badge-info">已代付</span>';
                        }else if (value === 6) {
                            return '<span class="badge badge-warning">审核中</span>' +
                                '<a class="btn btn-info btn-xs ' + '" href="#" onclick= "orderAudit(\'' + row.code + '\', 1)"><i class="fa fa-refresh"></i>通过</a> '+
                                '<a class="btn btn-danger btn-xs ' + '" href="#" onclick= "orderAudit(\'' + row.code + '\', 2)"><i class="fa fa-refresh"></i>拒绝</a> ';
						}
					}
				},
                {
                    field : 'merchantNotifyStatus',
                    title : '商户通知状态',
                    formatter: function (value, row, index) {
                        if (value === 0) {
                            return '<a class="btn btn-danger btn-xs ' + '" href="#" onclick= "notifyConfirm(\'' + row.code + '\')"><i class="fa fa-refresh"></i>未通知</a> ';
                        }
                        if (value === 1) {
                            return '<span class="badge badge-info">已通知</span>';
                        }
                        if (value === -1) {
                            return '<span class="badge badge-warning">无效</span>';
						}
                    }
                },
				{
					field : 'merchantId',
					title : '商户标识',
                    visible: false
				},
				{
					field : 'merchantName',
					title : '商户名称',
				},
				{
					field : 'merchantCode',
					title : '商户编码',
				},
				{
					field : 'channelId',
					title : '渠道标识',
                    visible: false
				},
				{
					field : 'channelName',
					title : '渠道名称',
				},
				{
					field : 'channelCode',
					title : '渠道编码',
				},
				{
					field : 'channelWithdrawalFee',
					title : '渠道代付手续费(元)',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                            return data;
                        }
                    }
				},
				{
					field : 'channelMchWithdrawalFee',
					title : '商户代付手续费(元)',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                            return data;
                        }
                    }
				},
				{
					field : 'walletKindId',
					title : '钱包标识',
                    visible: false
				},
				{
					field : 'walletKindName',
					title : '钱包名称',
				},
				{
					field : 'walletKindCode',
					title : '钱包编码',
				},
				{
					field : 'bankName',
					title : '银行名称',
				},
				{
					field : 'bankCode',
					title : '银行编码',
				},
				{
					field : 'bankBranch',
					title : '分行',
				},
				{
					field : 'bankSubBranch',
					title : '支行',
                   
				},
				{
					field : 'bankProvince',
					title : '所在省',
				},
				{
					field : 'bankCity',
					title : '所在市',
				},
				{
					field : 'bankUnionNo',
					title : '联行号',
				},
				{
					field : 'bankAccountOwner',
					title : '户主',
				},
				{
					field : 'bankAccountNo',
					title : '账户号',
				},
				{
					field : 'bankAccountType',
					title : '账户类型',
                    formatter: function (value, row, index) {
                        if (value === 0) {
                            return '<span>对私</span>';
                        }else if (value === 1) {
                            return '<span>对公</span>';
                        }
                    }
				},
				{
					field : 'callbackUrl',
					title : '回调地址',
                    visible: false
				},
                {
                    field : 'expires',
                    title : '失效时间',
                    visible: false
                },
                {
                    field : 'end',
                    title : '结束时间',
                },
                {
                    field : 'remarks',
                    title : '备注',
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });


        // 初始化查询
        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.begin = $("#begin").val();
            return search;
        }

        // 重置搜索条件
		function resetWithdrawalParam(formId) {
            var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
            $("#" + currentId)[0].reset();
            $form.find("input[name='begin']").val(nowTime);
        }

        // 搜索
        function withdrawalSearch(formId) {
            var begin = $form.find("input[name='begin']").val();
            if (begin) {
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                var params = $("#" + $.table._option.id).bootstrapTable('getOptions');
                params.queryParams = function(params) {
                    var search = {};
                    $.each($("#" + currentId).serializeArray(), function(i, field) {
                        search[field.name] = field.value;
                    });
                    search.pageSize = params.limit;
                    search.pageNum = params.offset / params.limit + 1;
                    search.searchValue = params.search;
                    search.orderByColumn = params.sort;
                    search.isAsc = params.order;
                    return search;
                }
                $("#" + $.table._option.id).bootstrapTable('refresh', params);
			} else {
                $.modal.alertWarning("请选择时间");
                return;
			}
        }

        /*时间控件*/
        // laydate input_time 时间控件绑定
        if ($(".input_time").length > 0) {
            layui.use('laydate', function () {
                var com = layui.laydate;
                $(".input_time").each(function (index, item) {
                    var time = $(item);
                    // 控制控件外观
                    var type = time.attr("data-type") || 'month';
                    // 控制回显格式
                    var format = time.attr("data-format") || 'yyyy-MM';
                    // 控制日期控件按钮
                    var buttons = time.attr("data-btn") || 'now|confirm', newBtnArr = [];
                    // 日期控件选择完成后回调处理
                    var callback = time.attr("data-callback") || {};
                    if (buttons) {
                        if (buttons.indexOf("|") > 0) {
                            var btnArr = buttons.split("|"), btnLen = btnArr.length;
                            for (var j = 0; j < btnLen; j++) {
                                if ( "now" === btnArr[j] || "confirm" === btnArr[j]) {
                                    newBtnArr.push(btnArr[j]);
                                }
                            }
                        } else {
                            if ( "now" === buttons || "confirm" === buttons) {
                                newBtnArr.push(buttons);
                            }
                        }
                    } else {
                        newBtnArr = ['now', 'confirm'];
                    }
                    com.render({
                        elem: item,
                        theme: 'molv',
                        trigger: 'click',
                        type: type,
                        format: format,
                        btns: newBtnArr,
                        done: function (value, data) {
                            if (typeof window[callback] != 'undefined'
                                && window[callback] instanceof Function) {
                                window[callback](value, data);
                            }
                        }
                    });
                });
            });
        }


        /*
        * 核销
        */
        function verification() {
            var url = prefix + "/verification";
            $.modal.open("核销", url);
        }

        /**
		 *支付状态查询
         */
        function orderConfirm(id) {
            $.modal.loading("正在处理中，请稍后...");
            $.modal.disable();
            $.post(prefix + "/payConfirm", {"id":id},function (response) {
                 if (response.code == 0) {
                     $.modal.alertSuccess("状态发生改变");
                     $.modal.closeLoading();
                     $.table.refresh();
				 } else {
                     if (response.msg == "支付订单保持"){
                         $.modal.alertError("状态未改变");
                         $.modal.closeLoading();
					 }else {
                         $.modal.alertError(response.msg);
                         $.modal.closeLoading();
                         $.table.refresh();
					 }
				 }
			});
        }


        /**
		 * 商户通知状态查询
         */
        function notifyConfirm(code) {
            $.modal.loading("正在处理中，请稍后...");
            $.modal.disable();
            $.post(ctx + "transaction/transactionPay/notifyConfirm", {'platFromCode':code,"type":1},function (response) {
                if (response.code == 0) {
                    $.modal.alertSuccess(response.msg);
                    $.modal.closeLoading();
                    $.table.refresh();
                } else {
                    $.modal.alertError(response.msg);
                    $.table.refresh();
                    $.modal.closeLoading();
                }
            });
        }


        /**
		 * 确认失败、确认放款
         */
        function confirmWithdawal(code,type) {
            $.modal.loading("正在处理中，请稍后...");
            $.modal.disable();
            $.post(prefix + "/confirmWithdawal", {"code":code,"type":type},function (response) {
                if (response.code == 0) {
                    $.modal.alertSuccess(response.msg);
                    $.modal.closeLoading();
                    $.table.refresh();
                } else {
                    $.modal.alertError(response.msg);
                    $.modal.closeLoading();
                    $.table.refresh();
                }
            });
        }


        /**
		 * 审核   通过、拒绝
         */
        function orderAudit(code, type) {
            $.modal.loading("正在处理中，请稍后...");
            $.modal.disable();
            $.post(prefix + "/orderAudit", {"code":code,"type":type},function (response) {
                if (response.code == 0) {
                    $.modal.alertSuccess(response.msg);
                    $.modal.closeLoading();
                    $.table.refresh();
                } else {
                    $.modal.alertError(response.msg);
                    $.modal.closeLoading();
                    $.table.refresh();
                }
            });
        }
	</script>
</body>
</html>